package com.learn.hystrix.demo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 测试超时降级服务
 *
 * @author Sunxiaoyu
 * Create in 17:42 2018/12/23
 */
@Service
public class HelloService {

    /**
     * 休眠5秒钟，执行降级服务（默认2000ms超时）
     *
     * @return 结果
     * @throws InterruptedException 异常
     */
    @HystrixCommand(fallbackMethod = "fallback")
    public String helloService() throws InterruptedException {
        TimeUnit.MILLISECONDS.sleep(5000);

        return "hello service";
    }

    private String fallback() {
        return "error";
    }
}
